<?php

namespace Config;

/**
 * MemBaseConfig short summary.
 *
 * MemBaseConfig description.
 *
 * @version 1.0
 * @author 张云江
 */
class MemBaseConfig
{
    /**
     * 设置redis配置
     * @param mixed $configname 配置名
     * @param mixed $host 主机名
     * @param mixed $port 主机端口
     * @param mixed $key 全局变量键
     */
    protected static function setConfig_G($key, $configname, $host, $port = 11211)
    {
        $data = null;
        if (array_key_exists($key, $GLOBALS))
            $data = $GLOBALS[$key];
        if (!is_array($data))
            $data = array();
        $data[$configname] = array(
            "host" => $host,
            "port" => $port
        );
        $GLOBALS[$key] = $data;
    }
    /**
     * 获取所有配置
     * @param mixed $key 全局变量键
     * @return void
     */
    protected static function getConfigWithAll_G($key)
    {
        return $GLOBALS[$key];
    }
    /**
     * 获取缓存配置
     * @param mixed $configname 配置名
     * @param mixed $key 全局变量键
     * @return mixed
     */
    protected static function getConfig_G($key, $configname)
    {
        $data = $GLOBALS[$key];
        if (!array_key_exists($configname, $data)) {
            return null;
        }
        return $data[$configname];
    }
    /**
     * 获取配置host值
     * @param mixed $key 全局键
     * @param mixed $configname 配置键
     * @return mixed
     */
    protected static function getConfig_GWithHost($key, $configname)
    {
        $data = self::getConfig_G($key, $configname);
        return $data["host"];
    }
    /**
     * 获取配置port值
     * @param mixed $key 全局键
     * @param mixed $configname 配置键
     * @return mixed
     */
    protected static function getConfig_GWithPort($key, $configname)
    {
        $data = self::getConfig_G($key, $configname);
        return $data["port"];
    }
}
